/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.qihoo.stat;

import android.content.Context;
import android.text.TextUtils;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.Vector;
import org.json.JSONObject;

public class u {
    private static String c = "QEvent";
    public static Vector a = null;
    public static boolean b = false;
    private static Context d = null;

    public static void a(Context paramContext, i parami) {
        d = paramContext;
        a(parami);
        d = null;
    }

    public static void a(i parami) {
        if (TextUtils.isEmpty(parami.a))
            return;
        if (a == null)
            a = new Vector();
        a.add(parami);
        b = true;
        if ((ac.a()) || (d == null))
            return;
        ai.b(ai.v(d), parami.a().toString() + "\n");
    }

    public static void b(Context paramContext, i parami) {
        d = paramContext;
        b(parami);
        d = null;
    }

    public static void b(i parami) {
        if (TextUtils.isEmpty(parami.a))
            return;
        if (a == null)
            a = new Vector();
        parami.c = "begin";
        parami.d = ai.o();
        boolean bool = false;
        i locali = null;
        for (int i = 0; i < a.size(); ++i) {
            locali = (i) a.get(i);
            if ((!(parami.a.equals(locali.a))) || (!(parami.c.equals(locali.c))))
                continue;
            bool = true;
            break;
        }
        x.a(c, "bExist: " + bool);
        if (bool)
            return;
        a.add(parami);
        b = true;
        if (ac.a())
            return;
    }

    public static void c(Context paramContext, i parami) {
        d = paramContext;
        c(parami);
        d = null;
    }

    public static void c(i parami) {
        if (TextUtils.isEmpty(parami.a))
            return;
        if (a == null)
            a = new Vector();
        parami.c = "end";
        parami.e = ai.o();
        boolean bool1 = false;
        boolean bool2 = false;
        i locali1 = null;
        i locali2 = null;
        i locali3 = null;
        for (int i = 0; i < a.size(); ++i) {
            locali1 = (i) a.get(i);
            if ((parami.a.equals(locali1.a)) && (parami.c.equals(locali1.c)) && (locali1.f < 0L)) {
                locali3 = locali1;
                bool1 = true;
            }
            if ((!(parami.a.equals(locali1.a))) || (!("begin".equals(locali1.c))))
                continue;
            locali2 = locali1;
            bool2 = true;
        }
        x.a(c, "bEndExist: " + bool1 + ", bBeginExist: " + bool2);
        if ((bool1) || (!(bool2)))
            return;
        a.remove(locali2);
        if (locali2.g != null) {
            if (parami.g == null)
                parami.g = new HashMap();
            Map.Entry localEntry = null;
            String str1 = null;
            String str2 = null;
            Iterator localIterator = locali2.g.entrySet().iterator();
            while (localIterator.hasNext()) {
                localEntry = (Map.Entry) localIterator.next();
                str1 = (String) localEntry.getKey();
                str2 = (String) localEntry.getValue();
                if (str2 == null)
                    continue;
                if (parami.g.containsKey(str1)) {
                    if (str2.equals(parami.g.get(str1)))
                        continue;
                    parami.g.put(str1, str2 + "," + ((String) parami.g.get(str1)));
                }
                else {
                    parami.g.put(str1, str2);
                }
            }
        }
        parami.d = locali2.d;
        parami.f = (parami.e - parami.d);
        a.add(parami);
        b = true;
        if ((ac.a()) || (d == null))
            return;
        ai.b(ai.v(d), parami.a().toString() + "\n");
    }

    public static void a() {
        if (a != null) {
            for (int i = 0; i < a.size(); ++i) {
                if ("begin".equals(((i) a.get(i)).c))
                    continue;
                a.remove(i);
                --i;
            }
            if (a.size() == 0) {
                a.clear();
                a = null;
            }
        }
        b = false;
    }
}